import { Directive } from '@angular/core';
import { AbstractControl, NG_VALIDATORS, Validator, ValidationErrors } from '@angular/forms';

@Directive({
  selector: '[appForbidCn]',
  providers: [{ provide: NG_VALIDATORS, useExisting: ForbiddenCnDirective, multi: true }]
})
export class ForbiddenCnDirective implements Validator {
  constructor() { }
  validate(control: AbstractControl): ValidationErrors | null {
    return /^(?:[\u4e00-\u9fa5]+)(?:[\u4e00-\u9fa5]+)*$/.test(control.value) ? { forbidCn: '密码不支持中文' } : null;
  }

}
